package com.ruoyi.web.controller.ring.app;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ring.domain.RingHrv;
import com.ruoyi.ring.domain.dto.RingHrvDTO;
import com.ruoyi.ring.domain.vo.RingHrvVO;
import com.ruoyi.ring.service.IRingHrvService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 心率变异性 （APP）
 */
@Slf4j
@RestController
@RequestMapping("/ring/app/ring_hrv")
public class AppHrvController extends BaseController
{
    @Resource
    private IRingHrvService ringHrvService;


    /**
     * 上报心率变异性-app
     */
    @Log(title = "上报心率变异性", businessType = BusinessType.INSERT)
    @PostMapping("add-hrv")
    public AjaxResult addHeartRate(@RequestBody RingHrv ringHrv)
    {
        ringHrv.setDailyValue(DateUtils.dateTime(DateUtils.YYYY_MM_DD, DateUtils.getDate()));
        ringHrv.setEndTime(new Date());
        return toAjax(ringHrvService.insertRingHrv(ringHrv));
    }
    /**
     * 心率变异性最新信息-app
     */
    @GetMapping("/query-hrv")
    public AjaxResult queryHeartRate(RingHrvDTO ringHrvDTO)
    {
        long userId = SecurityUtils.getUserId();
        log.info("心率变异性最新信息queryHeartRate: userId={}, param={}", userId, JSON.toJSONString(ringHrvDTO));
        RingHrvVO ringHrvVO = ringHrvService.queryRingHrv(ringHrvDTO);
        return AjaxResult.success(ringHrvVO);
    }
    /**
     * 心率变异性列表-app
     */
    @GetMapping("/query-list")
    public AjaxResult queryList(RingHrvDTO ringHrvDTO)
    {
        long userId = SecurityUtils.getUserId();
        log.info("心率变异性列表queryList: userId={}, param={}", userId, JSON.toJSONString(ringHrvDTO));
        List<RingHrv> list = ringHrvService.queryRingHrvList(ringHrvDTO);
        return AjaxResult.success(list);
    }
}
